#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: shijianbo
@Email:
@Time: 2022/7/12 10:50
@File: mysql.py
"""
import jaydebeapi
import pymysql

from .basic import DatabaseUtil


class MysqlUtil(DatabaseUtil):

    def __init__(self, user, password, ip, port=3306, **kwargs):
        self.CURSOR = {}
        server = kwargs.get('server', '')
        self.db = pymysql.connect(user=user, password=password, host=ip, port=port, database=server, autocommit=True)


class MysqlJdbcUtil(DatabaseUtil):

    def __init__(self, user, password, ip, port=3306, **kwargs):
        self.CURSOR = {}
        driver = 'com.mysql.cj.jdbc.Driver'
        server_name = kwargs.get('service', '')
        url = f'jdbc:mysql://{ip}:{port}/{server_name}?characterEncoding=UTF8&&useOldAliasMetadataBehavior=true'
        jar_ile = kwargs.get('jar_files')
        self.db = jaydebeapi.connect(driver, url, [user, password], jar_ile)
        self.db.jconn.setAutoCommit(False)


